package com.stylefeng.guns.rest.modular.App.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.Tools.Result;
import com.stylefeng.guns.rest.common.annotion.SSO;
import com.stylefeng.guns.rest.modular.App.model.TaskReleaseReason;
import com.stylefeng.guns.rest.modular.App.service.ITaskReleaseReasonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = {"/gunsApi/auth/taskReleaseReason"})
@Api(value = "驾驶员拒绝任务或释放任务原因字典操作相关api", tags = {"驾驶员拒绝任务或释放任务原因字典操作接口"})
@Slf4j(topic = "驾驶员拒绝任务或释放任务原因字典")
public class TaskReleaseReasonController extends BaseController {
    @Autowired
    private ITaskReleaseReasonService taskReleaseReasonService;

    /**
     * 分页获取驾驶员拒绝任务或释放任务原因字典列表
     * @param taskReleaseReason
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "分页获取驾驶员拒绝任务或释放任务原因字典列表", notes = "分页获取驾驶员拒绝任务或释放任务原因字典列表", httpMethod = "POST")
    @PostMapping(value = "/pageList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SSO
    public Result pageList(
            @RequestBody @ApiParam(name = "taskReleaseReason", value = "驾驶员拒绝任务或释放任务原因字典对象") TaskReleaseReason taskReleaseReason,
            @ApiParam(name = "pageNum", value = "当前页数", required = true) @RequestParam(value = "pageNum", defaultValue = "1",required = true) Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页显示条数", required = true) @RequestParam(value = "pageSize",defaultValue = "1000",required = true) Integer pageSize
    ) {
     try {
            Pager pager=new Pager();
            pager.setPageNumber(pageNum);//页码从1 开始
            pager.setPageSize(pageSize);
            pager.setObj(taskReleaseReason);
            Map map=taskReleaseReasonService.pageListTaskReleaseReason(pager,getToken());
            return  Result.success(map);
        }catch(Exception e){
         return Result.error(e.getMessage(),500100);
        }
    }

    /**
     * 获取驾驶员拒绝任务或释放任务原因字典列表
     * @param taskReleaseReason
     * @return
     */
    @ApiOperation(value = "获取驾驶员拒绝任务或释放任务原因字典列表", notes = "获取驾驶员拒绝任务或释放任务原因字典列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @SSO
    public Result list(
            @RequestBody @ApiParam(name = "taskReleaseReason", value = "驾驶员拒绝任务或释放任务原因字典对象")TaskReleaseReason taskReleaseReason) {
        Map map_=new LinkedHashMap<>();
        try {
            List<TaskReleaseReason> list=taskReleaseReasonService.selectListTaskReleaseReason(taskReleaseReason,getToken());
            return Result.success(list);
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 通过主键获取驾驶员拒绝任务或释放任务原因字典对象
     * @param id
     * @return
     */
    @ApiOperation(value = "通过主键获取驾驶员拒绝任务或释放任务原因字典对象", notes = "通过主键获取驾驶员拒绝任务或释放任务原因字典对象", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @SSO
    public Result getById(@ApiParam(name = "id", value = "主键ID", required = true) @RequestParam(value = "id", required = true) String  id) {
        Map map_=new LinkedHashMap<>();
        try {
            TaskReleaseReason taskReleaseReason=taskReleaseReasonService.findTaskReleaseReasonById(id,getToken());
            return Result.success(taskReleaseReason);
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }

    private String getToken(){
        return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
